<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2.7.v-for指令-根据数据生成列表结构</title>

    <script src="vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="button" value="添加数据" @click="add">
        <input type="button" value="移除数据" @click="remove">
        <ul>
            <li v-for="(it,index) in arr" :key="index">
                {{index+1}}我在:{{it}}
            </li>
        </ul>
        <h3 v-for="item in vegetables" v-bind:title="item.name">
            {{item.name}}
        </h3>
    </div>
    <script>
        let app = new Vue({
            el: "#app",
            data: {
                arr: ["济南", "上海", "北京", "江苏"],
                vegetables: [
                    { name: "西蓝花炒蛋" },
                    { name: "西红柿炒鸡蛋" }
                ]
            },
            methods: {
                add: function () {
                    this.vegetables.push({ name: "黄瓜炒菜" });
                },
                remove: function () {
                    this.vegetables.shift();
                }
            },
        })
    </script>
</body>

</html>